<?php
/**
 * @author Radovan Dvorsky
 * @version 20100514
 */
require_once ('library/My/Form/AjaxForm.php');

class Form_Block_AddProgram extends My_Form_AjaxForm {
	
	private $_programmes;
	
	public function init(){
		
		$cache = Zend_Registry::get('cache');
		$cacheName = My_Support::getCacheName('programmes','fetchAll');
		
		if(!($this->_programmes = $cache->load($cacheName))){
			$stOboryMapper = new Db_Mapper_StObory();
			$order = $stOboryMapper->getTable()->select()->order('Obor');
			$this->_programmes = $stOboryMapper->fetchAll($order);
			$cache->save($this->_programmes,$cacheName);		
		}		
	}
	
	function __construct($url, $update, $format = 'html',$options = null) {
		parent::__construct($options);
		
		$this->setMethod('post');
		
		$this->setJqueryParams(array(
				'url' => $url,
				'update' => $update,
				'format' => $format,
				'append' => true			
			)			
		);
		
		$programmes = new Zend_Form_Element_Select('Id_oboru');
		$programmes->setDecorators(array('ViewHelper'));	
		
		foreach($this->_programmes as $program){
			$programmes->addMultiOption($program->Id_oboru,$program->Obor);
		}
		
		$submit = new Zend_Form_Element_Button('submitProgramms');
		$submit->setDecorators(array('ViewHelper'))
		->setLabel('Pridať');
		
		$bid = new Zend_Form_Element_Hidden('bid');
		$bid->setDecorators(array('ViewHelper'));
		
		$this->addAjaxableElements(array($programmes,$bid));
		$this->setSender($submit,'onClick');
		
		$this->addElements(array($programmes,$bid,$submit));
	}
}

?>